import React, { useEffect, useState } from 'react';
import { UserAuth } from '../../utils/hooks';
import NotAuth from '../../components/NotAuth';
import { Button, Layout, message, Modal, Table, Row, Col, Input } from 'antd';
import { Content, Header } from 'antd/lib/layout/layout';
import axios from 'axios';
import Config from '../../Config';

const ExamineHis = () => {
  const [tableLoading, SetLoading] = useState(false);
  const [hisData, SetHis] = useState([]);
  const [refresh, Setfresh] = useState(true);
  useEffect(() => {
    SetLoading(true);
    axios
      .get(Config.baseURL + '/instrument/getMyExamineHis')
      .then(res => {
        if (res.data.code == 1) {
          let data = res.data.data;
          SetHis(data);
          SetLoading(false);
        } else if (res.data.code >= 10000) {
          message.error('获取失败 ' + res.data.message, 2);
          SetLoading(false);
        }
      })
      .catch(err => {
        message.error('后台出错 ' + err, 2);
        SetLoading(false);
      });
  }, []);
  const columns = [
    {
      title: '序号',
      dataIndex: 'id',
      key: 'id',
    },
    {
      title: '审核编号',
      dataIndex: 'examId',
      key: 'examId',
    },
    {
      title: '操作类型',
      dataIndex: 'type',
      key: 'type',
      filters: [
        { text: '录入', value: 1 },
        { text: '修改', value: 2 },
        { text: '删除', value: 3 },
      ],
      onFilter: (value, record) => record.type === value,
      render: (_, record) => {
        if (record.type == 1) {
          return <span>录入</span>;
        } else if (record.type == 2) {
          return <span>修改</span>;
        } else if (record.type == 3) {
          return <span>删除</span>;
        }
      },
    },
    {
      title: '仪器名称',
      dataIndex: 'YQMC',
      key: 'YQMC',
    },
    {
      title: '申请人',
      dataIndex: 'registerName',
      key: 'registerName',
    },
    {
      title: '录入时间',
      dataIndex: 'time',
      key: 'time',
    },
    {
      title: '是否通过',
      dataIndex: 'pass',
      key: 'pass',
      render: (_, value) => {
        return <span>{value.pass == 1 ? '通过' : '不通过'}</span>;
      },
    },
    {
      title: '审核人',
      dataIndex: 'username',
      key: 'username',
    },
    {
      title: '操作时间',
      dataIndex: 'time',
      key: 'time',
    },
  ];
  return (
    <>
      <Layout>
        <Header
          style={{
            borderRadius: '5px 5px 0px 0px',
            height: '40px',
            padding: '0px 15px',
            margin: '0px 0px',
            backgroundColor: 'white',
            textAlign: 'left',
            lineHeight: '40px',
          }}
        >
          <h3>仪器审核</h3>
        </Header>
        <Content style={{ padding: '10px 20px', backgroundColor: 'white' }}>
          <Table
            style={{ border: '2px solid #E6F7FF', borderRadius: '2px' }}
            loading={tableLoading}
            columns={columns}
            dataSource={hisData}
          ></Table>
        </Content>
      </Layout>
    </>
  );
};

export default () => {
  const { authority } = UserAuth('ExamineHis');
  return <>{authority ? <ExamineHis /> : <NotAuth />}</>;
};
